package lion.web.interceptors.virtual;

import lion.dev.io.FileUtil;

import org.apache.commons.lang.StringUtils;

/**
 * @author lion
 * @email hl_0074@sina.com
 * @date 2014年6月14日
 */
public class VirtualPath {

	private String prefix;
	private String location;

	private String[] locations;

	public VirtualPath(String prefix, String location) {

		this.prefix = prefix;
		this.location = location;
		locations = this.location.split(",");
	}

	public String getRealPath(String path) {

		String result = null;
		for (String loc : this.locations) {
			result = loc + "/" + path.substring(this.prefix.length());
			if (FileUtil.exists(result)) {
				break;
			}
		}
		return result;

	}

	public boolean matches(String path) {

		return StringUtils.startsWith(path, this.prefix);
	}

}
